package com.jyr.ohs.common;

import lombok.*;

/**
 * @author ZhongJing </p>
 * @Description 统一JSON返回 </p>
 * @date 2021/4/13 1:38 下午 </p>
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
@ToString
@EqualsAndHashCode
public class UnifiedJsonReturn<T> {

    private static final String SUCCESS = "SUCCESS";

    public static final String FAILED = "FAILED";

    /**
     * 是否成功
     */
    private String result;

    /**
     * 返回信息
     */
    private String message;

    /**
     * 返回数据
     */
    private T data;

    /**
     * 成功
     */
    public UnifiedJsonReturn<T> success() {
        this.setResult(SUCCESS);
        return this;
    }

    /**
     * 失败
     */
    public UnifiedJsonReturn<T> failed() {
        this.setResult(FAILED);
        return this;
    }

    /**
     * 添加信息
     * @param message 信息
     */
    public UnifiedJsonReturn<T> message(String message) {
        this.message = message;
        return this;
    }

    /**
     * 添加数据
     * @param data 数据
     */
    public UnifiedJsonReturn<T> data(T data) {
        this.data = data;
        return this;
    }

}
